<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--360浏览器优先以webkit内核解析-->
    <title>标签管理</title>
    <link rel="shortcut icon" href="assets/manager/favicon.ico"> 
    <link href="assets/manager/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="assets/manager/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="assets/manager/css/animate.css" rel="stylesheet">
    <link href="assets/manager/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div><h2 class="crumbs">标签管理</h2></div>
        <div class="row">
            <div class="col-sm-3">
                <span class="userMbq">标签名：</span>
                <input type="text" class="form-control userMsleinp">
            </div>
            <div class="col-sm-1"><button type="button" class="btn btn-outline btn-info">搜索</button></div>
        </div>
        <div class="row" style="margin-bottom: 5px;">
            <a href="addtag" type="button" class="btn btn-outline btn-info">添加标签</a>
        </div>
        <div class="row">
            <div class="ibox float-e-margins">
                <table class="table table-bordered usersTab">
                    <thead>
                        <tr>
                            <th width="5%">#</th>
                            <th width="20%">标签名</th>
                            <th width="20%">操作</th>
                        </tr>
                    </thead>
                    <tbody id="tagList">
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div id="editTagBox" class="ibox float-e-margins p10" style="display:none;">
                	<h3>修改标签</h3>
                    <div class="form-group">
                        	标签名：
                        <input style="width:250px" id="tag" type="text" name="phone" placeholder="标签名">
                    </div>
                    <button class="btn btn-primary" id="editTag" type="submit">修改</button>
                    <button class="btn btn-white" id="close" type="submit">取消</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="assets/manager/js/jquery.min.js?v=2.1.4"></script>
    <script src="assets/manager/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="assets/manager/js/plugins/layer/layer.min.js"></script>
    <!-- Flot -->
    <script src="assets/manager/js/plugins/flot/jquery.flot.js"></script>
    <script src="assets/manager/js/plugins/flot/jquery.flot.tooltip.min.js"></script>
    <script src="assets/manager/js/plugins/flot/jquery.flot.resize.js"></script>
    <script src="assets/manager/js/plugins/flot/jquery.flot.pie.js"></script>
    <!-- 自定义js -->
    <script src="assets/manager/js/content.js"></script>
    <script src="assets/manager/js/pageBox.js"></script>
    <!--flotdemo-->
    <script type="text/javascript">
    $(document).ready(function(){
    	var $oldTagName;
    	getTags();
    	function getTags(){
    		$.get("getTags",function(data){
    			var $tbody=$("#tagList");
    			$("#tagList").find("tr").remove();
    			for(var i=0;i<data.length;i++){
    				$buttonTd = $("<td><button type='button' id='edit' data-name='" + data[i] + "' class='btn btn-outline btn-info'>编辑</button>"
            				+ "<button type='button' id='del' data-name='" + data[i] + "'  class='btn btn-outline btn-danger'>删除</button></td>");
    				var $tr = $("<tr><td>" + (i+1) + "</td><td>" + data[i] + "</td></tr>");
    				$tr.append($buttonTd);
    				$tbody.append($tr);
    			}
    		});
    	}
    	
    	$("#tagList").on("click","#edit",function(){
    		$oldTagName = $(this).attr("data-name");
    		$("#editTagBox").show();
    		var $tagName = $(this).attr("data-name");
    		$("#tag").val($tagName);
    	});
    	$("#close").click(function(){
    		$("#editTagBox").hide();
    		$("#tag").val("");
    	});
    	
    	$("#editTag").click(function(){
    		$.post("updateTag",{oldTagName:$oldTagName,newTagName:$("#tag").val()},function(data){
    			if(data == 1){
    				alert("修改成功！");
    				getTags();
    				$("#editTagBox").hide();
    	    		$("#tag").val("");
    			}
    		});
    	});
    	
    	$("#tagList").on("click","#del",function(){
    		var $del = confirm("确认要删除？");
    		if($del){
    			var $tagName = $(this).attr("data-name");
        		var $parentsTr = $(this).parents("tr");
        		$.get("delTag?tagName=" + $tagName,function(data){
        			if(data==1){
        				alert("删除成功！");
        				getTags();
        			}
        		});
    		}
    	});
    });
    </script>
</body>
</html>